package com.lxq.LeetCode.removeElement;

import java.util.Arrays;

public class Solution {
    public static void main(String[] args) {
        int[] nums = {2,2};
        System.out.println(removeElement(nums,2)+" "+ Arrays.toString(nums));
    }

    public static int removeElement(int[] nums, int val) {
        if (nums.length == 0) {
            return 0;
        }
        if (nums.length == 1) {
            if (nums[0] == val) {
                return 0;
            }
            return 1;
        }
        int pOper = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val){
                nums[pOper] = nums[i];
                pOper++;
            }
        }
        return pOper;
    }
}
